/**
 * 路线站点
 *
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService", '$modalInstance', 'onSelectRouteSite'];

    function controller ($scope, $state, $modal, MessageBox, MuseService, $modalInstance, onSelectRouteSite) {
        //初始化查询对象 和 分页对象
        app.regsiterCacheData($scope, $state);
        $scope.queryObj = $scope.queryObj || {};
        $scope.pagerObj = $scope.pagerObj || {};

        //获取列表
        $scope.getObjList = function (pageNo, pageSize) {
            var curPage = pageNo || $scope.pagerObj.currentPage || 1;
            var param = {
                page: curPage, pageSize: pageSize || $scope.pagerObj.pageSize,
                param: {
                    name: 'like ' + ($scope.queryObj.name ? $scope.queryObj.name : "")
                }
            };

            MuseService.postObj(baseServices_restfulUrl + "routeSite/search.json", param).success(
                function (data, status, headers, config) {
                    // console.log(data);
                    if (data.state == 0) {
                        var page = data.data;
                        $scope.routeSiteList = page.data;

                        //分页器
                        $scope.pagerObj = PageCtrl().page($scope.pagerObj, page.total, curPage);
                    }
                });
        };

        $scope.getObjList();

        //选择
        $scope.select = function (routeSite) {
            onSelectRouteSite(routeSite);
            $modalInstance.close("selected");
        };

        $scope.pageChanged = function () {
            PageCtrl().check($scope.pagerObj);
            $scope.getObjList($scope.pagerObj.currentPage, $scope.pagerObj.pageSize);
        }

        $scope.close = function () {
            $modalInstance.dismiss("cancel");
        };
    }

    controller.$inject = deps;
    app.lazy.controller("RouteSiteSelectController", controller);
});
